package com.kehutong.webchat.service.impl;

import org.coraframework.converter.util.StringUtil;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.execute.entity.FindPage;

import com.kehutong.webchat.entity.WeChatSetting;
import com.kehutong.webchat.service.WeChatSettingService;

/**
 * 
 * @author: Kaplan
 * @version: v1.0
 * @description: 微信配置默认业务逻辑类
 * @date:2021年6月3日
 */
public class WeChatSettingServiceImpl implements WeChatSettingService {
	
	@Inject
	private JdbcSession jdbcSession;

	@Override
	public void save(WeChatSetting weChatSetting) {
		jdbcSession.insert(weChatSetting);
	}

	@Override
	public void delete(String id) {
		jdbcSession.deleteById(WeChatSetting.class, id);
	}

	@Override
	public void update(WeChatSetting weChatSetting) {
		jdbcSession.updateById(weChatSetting);
	}

	@Override
	public Object get(String id) {
		return jdbcSession.findById(WeChatSetting.class, id);
	}

	@Override
	public Object page(JSONObject jsonObject) {
		FindPage<WeChatSetting> findPage = jdbcSession.findPage(WeChatSetting.class);
		if(!StringUtil.isEmpty(jsonObject.getString("type"))) {
			findPage.eq("type", jsonObject.get("type"));
		}
		return findPage.eq("deleted", false)
				.like("companyName", jsonObject.get("companyName"))
				.page(jsonObject)
				.exe();
	}

}
